$(function(){
        $(".btn").on("click",function(){
            var userName = $(".phone").val();
            var pwd = $(".pwd").val();
            var rePwd = $(".repwd").val();
            if(userName==""||pwd==""||rePwd==""){
                alert("所有信息不可为空，请确认！");
                return;
            }else if(pwd!=rePwd){
                alert("两次密码输入不一致！");
                return;
            }
       
            $.post("php/addUser.php",{
                "username":$(".phone").val(),
                "userpass":$(".pwd").val()
            },function(date){
                if(date=="success"){
					alert("注册成功");
                    location.href = "login1.html";
                }else if(date=="fail"){
					alert("已被注册");
					location = "register.html";
				}
            })
            
        });
    });
	
	function fun(resText){
		let oSpan = document.querySelector(".error-tips");
		
		oSpan.innerHTML = resText;
	}
	// var oPhone=document.querySelector(".phone");
	var oF = document.querySelector(".register-form");
	var oPwd=document.querySelector(".pwd")
	var oSpan = document.querySelectorAll(".error-tips");
	var regphone = /^1(3|5|6|8|7)\d{9}$/;
	var regPwd = /^.{6,13}$/;
	var flagon = false;
	$(".phone").blur(function(){
		if(regphone.test(this.value)){
			$.get("php/checkUser.php",
				{"username":$(".phone").val()},
				function(resText){
					console.log(resText);
					if(resText=="0"){
						oSpan[0].innerHTML ="已被注册";
					}
					else if(resText=="1"){
						oSpan[0].innerHTML ="可以注册";
					}
				})
		}else{
			flagon = false;
			oSpan[0].innerHTML = "输入不合法";
			
		}
	})
	oPwd.onblur = function(){
		if(regPwd.test(this.value)){
			flagon = true;
			oSpan[3].innerHTML = "";
		}else{
			flagon = false;
			oSpan[3].innerHTML = "输入不合法";
		}
	}
	oF.onsubmit = function(){
		if(oPhone && oPwd){
			return true;
		}else{
			return false;
		}
	}